
window.onload = function () {
    initInfo();
    findAll()
}
function initInfo() {
    axios.get("/user/getLoginUser").then(resp =>{
        let info = resp.data;
        if (info == ""){
            $("infoDiv").innerHTML = "请先<a href='/login.html'>登陆</a>";
        }
        else {
            $("infoDiv").innerHTML = `<h4>登录用户</h4> 
<input type='button' style='margin-left: 200px;' value='安全退出' onclick='exitSystem()'>
                                        <div style="display: flex">
                                            <img src="/productImg/${info.img}"/>
                                        </div>
                                           <div>
                                             用户名：${info.name}<br>
                                             用户邮箱：${info.mail}
                                          </div>`
        }
    })
}
function exitSystem() {
    axios.get("/user/destorySession").then(resp =>{
        if (resp.data =="ok"){
            initInfo();
        }
    });
}
function findAll() {
    let str = "";
    axios.get("/channel/findAll").then(resp =>{
        resp.data.forEach(n =>{
            str +=`<tr><td><a href="/stick.html?channelId=${n.channelId}">${n.name}</a></td>
                    <td>${n.description}</td><td>${n.stickNum}</td></tr>`
        });
        $("data").innerHTML = str;
    })
}
